//
//  LSZDGJZTableViewCell.m
//  JKFuYinProject
//
//  Created by 九酷 on 2017/12/20.
//  Copyright © 2017年 LC. All rights reserved.
//

#import "LSZDGJZTableViewCell.h"

@implementation LSZDGJZTableViewCell
-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.imageViewHeader = [[UIImageView alloc]init];
        [self.imageViewHeader.layer setMasksToBounds:YES];
        [self addSubview:self.imageViewHeader];
        
        self.imageViewGender = [[UIImageView alloc]init];
        [self addSubview:self.imageViewGender];

        self.labelName = [[UILabel alloc]init];
        self.labelName.textColor = titleColorLSZ;
        [self addSubview:self.labelName];

        self.labelTime= [[UILabel alloc]init];
        self.labelTime.textColor = lightColor;
        [self addSubview:self.labelTime];

        self.butFocusOn = [[UIButton alloc]init];
        self.butFocusOn.backgroundColor = redUIColor;
        [self.butFocusOn setTitle:@" + 关注" forState:UIControlStateNormal];
        [self.butFocusOn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        self.butFocusOn.titleLabel.font = FONT_(14);
        [self.butFocusOn.layer setMasksToBounds:YES];
        [LSZSpecialPackaging setLabelAdaptiveSize:self.butFocusOn.titleLabel font:15];
        [self addSubview:self.butFocusOn];

        self.labelType = [[UILabel alloc]init];
        self.labelType.textColor = lightColor;
        [self addSubview:self.labelType];

        self.labelBigType = [[UILabel alloc]init];
        self.labelBigType.textColor = lightColor;
        [self addSubview:self.labelBigType];

        self.imageViewYuan = [[UIImageView alloc]init];
        self.imageViewYuan.image = [UIImage imageNamed:@"橘色圆圈"];
        [self addSubview:self.imageViewYuan];

        self.labelSelect = [[UILabel alloc]init];
        self.labelSelect.backgroundColor = redUIColor;
        self.labelSelect.textAlignment = NSTextAlignmentCenter;
        [self.labelSelect.layer setMasksToBounds:YES];
        self.labelSelect.text = @"精选";
        self.labelSelect.textColor = [UIColor whiteColor];
        [self addSubview:self.labelSelect];

        self.labelTitle = [[UILabel alloc]init];
        self.labelTitle.textColor = titleColorLSZ;
        [self addSubview:self.labelTitle];

        self.imageViewUp = [[UIImageView alloc]init];
        [self.imageViewUp.layer setMasksToBounds:YES];
        [self.imageViewUp.layer setCornerRadius:5];
        [self addSubview:self.imageViewUp];

        self.labelConunt = [[UILabel alloc]init];
        self.labelConunt.numberOfLines = 5;
        self.labelConunt.textColor = titleColorLSZ;
        [self addSubview:self.labelConunt];

        self.labelBenediction = [[UILabel alloc]init];
        self.labelBenediction.textColor = lightColor;
        self.labelBenediction.textAlignment = NSTextAlignmentRight;
        [self addSubview:self.labelBenediction];

        if (ScreenWidth == 320) {
            //5
            self.labelName.font = FONT_(13.5);
            self.labelTime.font = FONT_(12.5);
            self.labelType.font = FONT_(11.5);
            self.labelBigType.font = FONT_(11.5);
            self.labelSelect.font = FONT_(13.5);
            self.labelTitle.font= FONT_(13.5);
            self.labelConunt.font = FONT_(13.5);
            self.labelBenediction.font = FONT_(12.5);
            self.imageViewHeader.frame = CGRectMake(15, 10, 37, 37);
            [self.imageViewHeader.layer setCornerRadius:18.5];
            self.imageViewGender.frame = CGRectMake(15+37-15,32,15,15);
            self.labelName.frame = CGRectMake(CGRectGetMaxX(self.imageViewHeader.frame)+10, 10.5, ScreenWidth/3*2, 15);
            self.labelTime.frame = CGRectMake(CGRectGetMaxX(self.imageViewHeader.frame)+10, CGRectGetMaxY(self.labelName.frame)+4.5,ScreenWidth-CGRectGetMaxX(self.imageViewHeader.frame)-10, 14);
            self.butFocusOn.frame = CGRectMake(ScreenWidth-10-70, CGRectGetMinY(self.imageViewHeader.frame)+5, 70,self.imageViewHeader.frame.size.height-10);
            [self.butFocusOn.layer setCornerRadius:self.butFocusOn.frame.size.height/2];
            self.labelType.frame = CGRectMake(ScreenWidth-50-43,(37-16)/2+CGRectGetMinY(self.imageViewHeader.frame), 50, 14);
            self.labelBigType.frame = CGRectMake(CGRectGetMinX(self.labelType.frame)-26, (37-14)/2+CGRectGetMinY(self.imageViewHeader.frame),26, 14);
            self.imageViewYuan.frame = CGRectMake(CGRectGetMinX(self.labelBigType.frame)-17,(37-14)/2+CGRectGetMinY(self.imageViewHeader.frame)+1, 12, 12);
            self.labelSelect.frame = CGRectMake(15, CGRectGetMaxY(self.imageViewHeader.frame)+10, 30, 16);
            [self.labelSelect.layer setCornerRadius:2];
            self.labelTitle.frame = CGRectMake(5+CGRectGetMaxX(self.labelSelect.frame), CGRectGetMaxY(self.imageViewHeader.frame)+10, ScreenWidth-10-CGRectGetMaxX(self.labelSelect.frame), 16);
            self.imageViewUp.frame = CGRectMake(15, CGRectGetMaxY(self.labelTitle.frame)+14, ScreenWidth-30, (ScreenWidth-30)/16*9);
            self.labelConunt.frame = CGRectMake(15, CGRectGetMaxY(self.imageViewUp.frame)+8, ScreenWidth-30, 65);
            self.labelBenediction.frame = CGRectMake(15, CGRectGetMaxY(self.labelConunt.frame), ScreenWidth-30, 14);
        }else if(ScreenWidth == 375){
            // 6 7
            self.labelName.font = FONT_(14);
            self.labelTime.font = FONT_(13);
            self.labelType.font = FONT_(12);
            self.labelBigType.font = FONT_(12);
            self.labelSelect.font = FONT_(14);
            self.labelTitle.font= FONT_(14);
            self.labelConunt.font = FONT_(14);
            self.labelBenediction.font = FONT_(13);
            self.imageViewHeader.frame = CGRectMake(15, 10, 38, 38);
            [self.imageViewHeader.layer setCornerRadius:19];
            self.imageViewGender.frame = CGRectMake(15+38-16,48-16,16,16);

            self.labelName.frame = CGRectMake(CGRectGetMaxX(self.imageViewHeader.frame)+10, 10.5, ScreenWidth/3*2, 18);
            self.labelTime.frame = CGRectMake(CGRectGetMaxX(self.imageViewHeader.frame)+10, CGRectGetMaxY(self.labelName.frame)+4.5,ScreenWidth-CGRectGetMaxX(self.imageViewHeader.frame)-10, 15);
            self.butFocusOn.frame = CGRectMake(ScreenWidth-10-70, CGRectGetMinY(self.imageViewHeader.frame)+5, 70,self.imageViewHeader.frame.size.height-10);
            [self.butFocusOn.layer setCornerRadius:self.butFocusOn.frame.size.height/2];
            self.labelType.frame = CGRectMake(ScreenWidth-50-43, (38-16)/2+CGRectGetMinY(self.imageViewHeader.frame) , 50, 15);
            self.labelBigType.frame = CGRectMake(CGRectGetMinX(self.labelType.frame)-28, (38-16)/2+CGRectGetMinY(self.imageViewHeader.frame),28, 15);
            self.imageViewYuan.frame = CGRectMake(CGRectGetMinX(self.labelBigType.frame)-17,(38-16)/2+CGRectGetMinY(self.imageViewHeader.frame)+1.5, 12, 12);
            self.labelSelect.frame = CGRectMake(15, CGRectGetMaxY(self.imageViewHeader.frame)+10, 32, 18);
            [self.labelSelect.layer setCornerRadius:2.5];
            self.labelTitle.frame = CGRectMake(5+CGRectGetMaxX(self.labelSelect.frame), CGRectGetMaxY(self.imageViewHeader.frame)+10, ScreenWidth-10-CGRectGetMaxX(self.labelSelect.frame), 18);
            self.imageViewUp.frame = CGRectMake(15, CGRectGetMaxY(self.labelTitle.frame)+14, ScreenWidth-30, (ScreenWidth-30)/16*9);
            self.labelConunt.frame = CGRectMake(15, CGRectGetMaxY(self.imageViewUp.frame)+8, ScreenWidth-30, 65);
            self.labelBenediction.frame = CGRectMake(15, CGRectGetMaxY(self.labelConunt.frame), ScreenWidth-30, 16);
        }else {
            //plus
            self.labelName.font = FONT_(15.5);
            self.labelTime.font = FONT_(15);
            self.labelType.font = FONT_(14);
            self.labelBigType.font = FONT_(14);
            self.labelTitle.font= FONT_(15.5);
            self.labelSelect.font = FONT_(15);//精选
            self.labelConunt.font = FONT_(15);
            self.labelBenediction.font = FONT_(14.5);

            self.imageViewHeader.frame = CGRectMake(15, 10, 39, 39);
            [self.imageViewHeader.layer setCornerRadius:19.5];
            self.imageViewGender.frame = CGRectMake(15+39-17,49-17,17,17);

            self.labelName.frame = CGRectMake(CGRectGetMaxX(self.imageViewHeader.frame)+10, 10.5, ScreenWidth/3*2, 20);
            self.labelTime.frame = CGRectMake(CGRectGetMaxX(self.imageViewHeader.frame)+10, CGRectGetMaxY(self.labelName.frame)+4.5,ScreenWidth-CGRectGetMaxX(self.imageViewHeader.frame)-10, 16);
            self.butFocusOn.frame = CGRectMake(ScreenWidth-10-70, CGRectGetMinY(self.imageViewHeader.frame)+5, 70,self.imageViewHeader.frame.size.height-10);
            [self.butFocusOn.layer setCornerRadius:self.butFocusOn.frame.size.height/2];
            self.labelType.frame = CGRectMake(ScreenWidth-50-43, (39-16)/2+CGRectGetMinY(self.imageViewHeader.frame), 50, 16);
            self.labelBigType.frame = CGRectMake(CGRectGetMinX(self.labelType.frame)-30, (39-16)/2+CGRectGetMinY(self.imageViewHeader.frame),30, 16);
            self.imageViewYuan.frame = CGRectMake(CGRectGetMinX(self.labelBigType.frame)-17,(39-16)/2+CGRectGetMinY(self.imageViewHeader.frame)+2, 12, 12);
            self.labelSelect.frame = CGRectMake(15, CGRectGetMaxY(self.imageViewHeader.frame)+10, 33, 20);
            [self.labelSelect.layer setCornerRadius:3];
            self.labelTitle.frame = CGRectMake(5+CGRectGetMaxX(self.labelSelect.frame), CGRectGetMaxY(self.imageViewHeader.frame)+10, ScreenWidth-10-CGRectGetMaxX(self.labelSelect.frame), 20);
            self.imageViewUp.frame = CGRectMake(15, CGRectGetMaxY(self.labelTitle.frame)+14, ScreenWidth-30, (ScreenWidth-30)/16*9);
            self.labelConunt.frame = CGRectMake(15, CGRectGetMaxY(self.imageViewUp.frame)+8, ScreenWidth-30, 65);
            self.labelBenediction.frame = CGRectMake(15, CGRectGetMaxY(self.labelConunt.frame), ScreenWidth-30, 18);
        }
    }
    return self;
}
-(void)setManager:(LSZPrayerAndTestimonyMg *)manager
{
    [self.imageViewHeader sd_setImageWithURL:[NSURL URLWithString:manager.publisher_pic] placeholderImage:[UIImage imageNamed:@"placeholder"]];
    self.imageViewUp.contentMode = UIViewContentModeScaleAspectFill;
    [self.imageViewUp sd_setImageWithURL:[NSURL URLWithString:manager.imageUrl] placeholderImage:[UIImage imageNamed:@"placeholder"]];
    if ([manager.gender isEqualToString:@"女"]) {
        self.imageViewGender.image = [UIImage imageNamed:@"性别女"];
    }else if ([manager.gender isEqualToString:@"男"]){
        self.imageViewGender.image = [UIImage imageNamed:@"性别男"];
    }else{

    }
    if([manager.publisher isEqualToString:@""]||manager.publisher.length == 0){
        self.labelName.text = [NSString stringWithFormat:@"SJ_%@",manager.uid];
    }else{
        self.labelName.text = manager.publisher;
    }
    NSString * strNumber = [LSZSpecialPackaging theNumberViewsForTheAlbumAhanges:manager.browseNum];
    self.labelTime.text = [NSString stringWithFormat:@"%@  %@  浏览%@",manager.location,[LSZSpecialPackaging GetThePreviousTimeAndCompareItNow:manager.createTime],strNumber];
    self.labelType.text = manager.typeName;

    if ([manager.is_follow isEqualToString:@"1"]) {
        [self.butFocusOn setTitle:@"已关注" forState:UIControlStateNormal];
        self.butFocusOn.backgroundColor =  partialShallow;
        self.butFocusOn.userInteractionEnabled = NO;
    }else{
        [self.butFocusOn setTitle:@" + 关注" forState:UIControlStateNormal];
        self.butFocusOn.backgroundColor = redUIColor;
        self.butFocusOn.userInteractionEnabled = YES;
    }

    CGFloat fontType;
    CGFloat heightType;
    CGFloat fontContent;
    if (ScreenWidth == 320) {
        //5
        fontType = 11.5;
        heightType = 14;
        fontContent = 13.5;
    }else if(ScreenWidth == 375){
        // 6 7
        fontType = 12;
        heightType = 15;
        fontContent = 14;
    }else {
        //plus
        fontType = 13;
        heightType = 17;
        fontContent = 15;
    }
    CGFloat width = [LSZSpecialPackaging caculateWidthOfText:ScreenWidth height:heightType font:fontType :manager.typeName];
    self.labelType.frame = CGRectMake(ScreenWidth-width-15+20, CGRectGetMinY(self.labelName.frame)+((self.imageViewHeader.frame.size.height-heightType)/2)-1, width, heightType);

    NSString *BigTypeStr = [[NSString alloc]init];;
    if ([manager.type isEqualToString:@"0"]) {
        BigTypeStr = @"祷告";
    }else{
        BigTypeStr = @"见证";
    }
    self.labelBigType.text = BigTypeStr;
    CGRect rect = self.labelBigType.frame;
    rect.origin.x = CGRectGetMinX(self.labelType.frame)-self.labelBigType.frame.size.width;
    self.labelBigType.frame = rect;

    CGRect rect2 = self.imageViewYuan.frame;
    rect2.origin.x = CGRectGetMinX(self.labelBigType.frame)-self.imageViewYuan.frame.size.width-2;
    self.imageViewYuan.frame = rect2;

    if([manager.type isEqualToString:@"0"]){
        if ([manager.publisher isEqualToString:@""]||manager.publisher.length == 0) {
            self.labelTitle.text = [NSString stringWithFormat:@"SJ_%@为%@关于%@的%@",manager.uid,manager.toName,manager.typeName,BigTypeStr];
        }else{
            self.labelTitle.text = [NSString stringWithFormat:@"%@为%@关于%@的%@",manager.publisher,manager.toName,manager.typeName,BigTypeStr];
        }
    }else{
        if ([manager.publisher isEqualToString:@""]||manager.publisher.length == 0) {
            self.labelTitle.text = [NSString stringWithFormat:@"SJ_%@为%@关于%@的%@",manager.id_id,manager.title,manager.typeName,BigTypeStr];
        }else{
            self.labelTitle.text = [NSString stringWithFormat:@"%@为%@关于%@的%@",manager.publisher,manager.title,manager.typeName,BigTypeStr];
        }
    }
    self.labelConunt.text = manager.content;

    CGFloat heightConunt = [LSZSpecialPackaging caculateWidthOfText:ScreenWidth-30 height:1000 font:fontContent :manager.content];
    self.labelConunt.frame = CGRectMake(15, CGRectGetMaxY(self.imageViewUp.frame)+8, ScreenWidth-30, heightConunt);
    [self.labelConunt sizeToFit];

    self.labelBenediction.frame = CGRectMake(15, self.frame.size.height-22, ScreenWidth-30, 14);
    self.labelBenediction.text = [NSString stringWithFormat:@"获得%@祝福",manager.praiseNum];
}
@end
